//
//  UIView+category.m
//  QQplayground
//
//  Created by 王昭的Mac Air on 2018/6/10.
//  Copyright © 2018年 zhang. All rights reserved.
//

#import "UIView+category.h"

@implementation UIView (category)

#pragma mark - 手势
//单击
- (void)addTapGestureRecognizerWithTarget:(id)target action:(SEL)sel
{
    self.userInteractionEnabled = YES;
    UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:target action:sel];
    [self addGestureRecognizer:tapGR];
}

//长按
- (void)addLongGestureRecognizerWithTarget:(id)target action:(SEL)sel
{
    self.userInteractionEnabled = YES;
    UILongPressGestureRecognizer *longGR = [[UILongPressGestureRecognizer alloc] initWithTarget:target action:sel];
    [self addGestureRecognizer:longGR];
}

//拖拽
- (void)addPanGestureRecognizerWithTarget:(id)target action:(SEL)sel
{
    self.userInteractionEnabled = YES;
    UIPanGestureRecognizer *panGR = [[UIPanGestureRecognizer alloc] initWithTarget:target action:sel];
    [self addGestureRecognizer:panGR];
}

//左滑
- (void)addLeftSwipeGestureRecognizerWithTarget:(id)target action:(SEL)sel
{
    self.userInteractionEnabled = YES;
    UISwipeGestureRecognizer *swipeGR = [[UISwipeGestureRecognizer alloc] initWithTarget:target action:sel];
    swipeGR.direction = UISwipeGestureRecognizerDirectionLeft;
    [self addGestureRecognizer:swipeGR];
}

//右滑
- (void)addRightSwipeGestureRecognizerWithTarget:(id)target action:(SEL)sel
{
    self.userInteractionEnabled = YES;
    UISwipeGestureRecognizer *swipeGR = [[UISwipeGestureRecognizer alloc] initWithTarget:target action:sel];
    swipeGR.direction = UISwipeGestureRecognizerDirectionRight;
    [self addGestureRecognizer:swipeGR];
}

//上滑
- (void)addUpSwipeGestureRecognizerWithTarget:(id)target action:(SEL)sel
{
    self.userInteractionEnabled = YES;
    UISwipeGestureRecognizer *swipeGR = [[UISwipeGestureRecognizer alloc] initWithTarget:target action:sel];
    swipeGR.direction = UISwipeGestureRecognizerDirectionUp;
    [self addGestureRecognizer:swipeGR];
}

//下滑
- (void)addDownSwipeGestureRecognizerWithTarget:(id)target action:(SEL)sel
{
    self.userInteractionEnabled = YES;
    UISwipeGestureRecognizer *swipeGR = [[UISwipeGestureRecognizer alloc] initWithTarget:target action:sel];
    swipeGR.direction = UISwipeGestureRecognizerDirectionDown;
    [self addGestureRecognizer:swipeGR];
}

//移除所有手势
- (void)removeAllGestureRecognizer
{
    for (UITapGestureRecognizer *tap in self.gestureRecognizers) {
        [self removeGestureRecognizer:tap];
    }
}

@end
